<template>
	<view class="pics">
		<scroll-view class="left"  scroll-y>
			<!-- 渲染左侧数据 -->
			<view  @click="leftClickHandle(index,item.id)"
			:class="active===index?'active':''" 
			v-for="(item,index) in cates" 
			:key="item.id">
				{{item.title}}
			</view>
			
		</scroll-view>
		<scroll-view class="right" scroll-y="">
			<view class="item"  v-for="item in secondData" :key="item.id">
				<image @click="previewImg(item.img_url)" :src="item.img_url"> </image>
				<text>{{item.title}}</text>
			</view>
			<text v-if="secondData.length === 0">暂无数据</text>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				cates:[],
				active:1,
				secondData:[],
				baseUrl : "http://localhost:62076"
			}
		},
		methods: {
			async getPicsCate(){
				const res = await this.$myRequest({
					url:'/api/shop/getimgcategory'
				})
				
				this.cates=res.data.message
			},
			//点击高亮方法
			async leftClickHandle(index,id){
				console.log(id)
				this.active=index
				
				//获取右侧数据
				const res = await this.$myRequest({
					url:'/api/shop/getimages?cateid='+id
				})
				console.log(res.data.message)
				this.secondData = res.data.message
				
			},
			//预览图片方法
			previewImg (current) {
							const urls = this.secondData.map(item=>{
								return this.baseUrl+item.img_url
							})
							console.log(urls)
							uni.previewImage({
								current,
								urls
							})
						},
			
			onLoad(){
				this.getPicsCate()
			}
		}
	}
</script>

<style lang="scss">
	page{
		height:100%;
	}
	.pics{
		height:100%;
		display:flex;
		.left{
			width:200rpx;
			height: 100%;
			border-right: 1px solid #eee;
			view{
				height: 60px;
				line-height: 60px;
				color: #333;
				text-align: center;
				font-size: 30rpx;
				border-top: 1px solid #eee;
			}
			.active{
				background: $shop-color;
				color: #fff;
			}
		}
		
		.right{
				height: 100%;
				width: 520rpx;
				margin: 10rpx auto;
				.item{
					image{
						width: 520rpx;
						height: 520rpx;
						border-radius: 5px;
					}
					text{
						font-size: 30rpx;
						line-height: 60rpx;
					}
				}
			}
	}

</style>
